﻿using ERPSystem.Common.Domains.WarehouseCommon;
using ERPSystem.Common.DTO;
using ERPSystem.Common.Infrastructure.IRepository;
using MediatR;

namespace BasicInformationCommon.API.BasicInformationCommons.WarehouseMateriales
{
    public class WarehouseMaterialQueryHandler : IRequestHandler<WarehouseMaterialQueryCommand, Result>
    {
        private readonly IBaseRepository<WarehouseMaterial> _warehouseMaterialRepository;

        public WarehouseMaterialQueryHandler(IBaseRepository<WarehouseMaterial> warehouseMaterialRepository)
        {
            _warehouseMaterialRepository = warehouseMaterialRepository;
        }
        /// <summary>
        /// 仓库料品表查询业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(WarehouseMaterialQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            try
            {
                var warehouseMaterialList = await(await _warehouseMaterialRepository.GetAll()).ToListAsync();
                result.Data = warehouseMaterialList;

            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
